//引入axios
import axios from "axios";
//引入qs
import qs from "qs";
//设置基本路由
let baseURL = "/api";





//请求拦截
axios.interceptors.request.use(req => {
    req.headers.authorization=localStorage.getItem("info")?JSON.parse(localStorage.getItem("info")).token:undefined;
    return req;
});

//响应拦截
axios.interceptors.response.use(res => {
      //登录拦截
      if(res.data.msg=="登录已过期或访问权限受限" || res.data.msg[0]=="请设置请求头,并携带验证字符串"){
        alert("请登录")
        return
    }
    console.log(res);
    return res.data;
});



// 封装get方法
export const get = (url, params={}) => {
    return axios.get(baseURL + url, {
        params
    });
};

// 封装post方法
export const post = (url, data = {}) => {
    console.log(data,111111111);
    return axios.post((baseURL + url), qs.stringify(data))
}

